/*
 * Copyright 2009 Thor Hovden
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the
 * License. 
 */
package eviva.structure;

import junit.framework.TestCase;

/**
 * Tests Mission Control functionality
 */
public class MissionControlTest extends TestCase {

	MissionControl mission = new MissionControl();
	MissionControl.Mission m0;

	public MissionControlTest(String sTestName) {
		super(sTestName);
	}

	protected void setUp() throws Exception {
		super.setUp();
		m0 = mission.set(0, "Set up infrastructure");
	}

	protected void tearDown() throws Exception {
		mission.complete(m0);
	}

	/**
	 * @see MissionControl#getMissionLog()
	 */
	public void testGetMissionLog() {
		MissionControl.Mission m4 = mission.set(4, "Test mission log");

		MissionControl planB = new MissionControl();
		String realResult = planB.getMissionLog();
		String expectedResult = "";
		assertEquals("Empty initial log", expectedResult, realResult);

		mission.complete(m4);
	}

	/**
	 * @see MissionControl#set(Integer,String)
	 */
	public void testSet() {
		MissionControl.Mission m4 = mission.set(4, "Test set");

		MissionControl planB = new MissionControl();
		planB.set(3, "B");
		planB.set(6, "C");
		String realResult = planB.getMissionLog();
		String expectedResult = "   B\n      C\n";
		assertEquals("Log after double mission set", expectedResult, realResult);

		mission.complete(m4);
	}

	/**
	 * @see MissionControl#configureIndentation(Character)
	 */
	public void testConfigureIndentation() {
		MissionControl.Mission m4 = mission.set(4, "Test configuration");

		MissionControl planB = new MissionControl();
		planB.set(3, "B");
		planB.configureIndentation('x');
		String realResult = planB.getMissionLog();
		String expectedResult = "xxxB\n";
		assertEquals("Log with new indentation during mission", expectedResult, realResult);

		mission.complete(m4);
	}

	/**
	 * @see MissionControl#complete(Integer,String)
	 */
	public void testComplete() {
		MissionControl.Mission m4 = mission.set(4, "Test completing mission");

		MissionControl planB = new MissionControl();
		MissionControl.Mission mb = planB.set(3, "B");
		planB.complete(mb);
		String realResult = planB.getMissionLog();
		String expectedResult = "";
		assertEquals("Cleaned log after mission complete", expectedResult, realResult);

		mission.complete(m4);
	}

	/**
	 * @see MissionControl#abort(Integer,String)
	 */
	public void testAbort() {
		MissionControl.Mission m4 = mission.set(4, "Test aborted mission");

		MissionControl planB = new MissionControl();
		MissionControl.Mission mb = planB.set(3, "B");
		planB.abort(mb, "Error");
		String realResult = planB.getMissionLog();
		String expectedResult = "   B\n   B ***ABORTED\n";
		assertEquals("Log after mission abort", expectedResult, realResult);

		mission.complete(m4);
	}

}
